<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Relations</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
MathJax = {
	tex: {
		inlineMath: '$', '$'], ['\\(', '\\)'
	},
	svg: {
		fontCache: 'global'
	}
};
</script>
<script type="text/javascript" id="MathJax-script" async
	src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>

<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Relations' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../extensions.html">Kits</a></li><li><a href="index.html">BasicInformKit</a></li><li><b>Relations</b></li></ul></div>
<p class="purpose">Relations  To manage run-time storage for relations between objects, and to find routes through relations and the map.</p>

<ul class="toc"><li><a href="rltns.html#SP1">&#167;1. Relation Records</a></li><li><a href="rltns.html#SP2">&#167;2. Valency Adjectives</a></li><li><a href="rltns.html#SP3">&#167;3. One To One Relations</a></li><li><a href="rltns.html#SP4">&#167;4. Symmetric One To One Relations</a></li><li><a href="rltns.html#SP5">&#167;5. Various To Various Relations</a></li><li><a href="rltns.html#SP6">&#167;6. Equivalence Relations</a></li><li><a href="rltns.html#SP7">&#167;7. Show Various to Various</a></li><li><a href="rltns.html#SP8">&#167;8. Show One to One</a></li><li><a href="rltns.html#SP9">&#167;9. Show Reversed One to One</a></li><li><a href="rltns.html#SP10">&#167;10. Show Equivalence</a></li><li><a href="rltns.html#SP11">&#167;11. Relation Emptying</a></li><li><a href="rltns.html#SP12">&#167;12. Relation Route-Finding</a></li><li><a href="rltns.html#SP13">&#167;13. One To Various Route-Finding</a></li><li><a href="rltns.html#SP14">&#167;14. Various To One Route-Finding</a></li><li><a href="rltns.html#SP15">&#167;15. Slow Various To Various Route-Finding</a></li><li><a href="rltns.html#SP16">&#167;16. Fast Various To Various Route-Finding</a></li><li><a href="rltns.html#SP17">&#167;17. Iterating Relations</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Relation Records.</b>See "RelationKind.i6t" for further explanation.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">RR_NAME</span><span class="plain-syntax">            </span><span class="constant-syntax">5</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">     </span><span class="constant-syntax">6</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">         </span><span class="constant-syntax">7</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">RR_KIND</span><span class="plain-syntax">            </span><span class="constant-syntax">8</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">RR_HANDLER</span><span class="plain-syntax">         </span><span class="constant-syntax">9</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">     </span><span class="constant-syntax">10</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Valency Adjectives.</b>These are defined in the Standard Rules; the following routines must either
test the state (if <span class="extract"><span class="extract-syntax">set</span></span> is negative), or change the state to <span class="extract"><span class="extract-syntax">set</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">VALENCY_MASK</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RELS_EQUIVALENCE</span><span class="plain-syntax">+</span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">+</span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">+</span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">RELATION_TY_EquivalenceAdjective</span><span class="plain-syntax"> </span><span class="identifier-syntax">rel</span><span class="plain-syntax"> </span><span class="identifier-syntax">set</span><span class="plain-syntax">  </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax"> </span><span class="identifier-syntax">handler</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_EQUIVALENCE</span><span class="plain-syntax">) </span><span class="identifier-syntax">state</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">set</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> + </span><span class="identifier-syntax">RELS_EQUIVALENCE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> + </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_EQUIVALENCE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RlnSetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">handler</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_HANDLER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">handler</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RELS_SET_VALENCY</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">VALENCY_MASK</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="string-syntax">"*** Can't change this to an equivalence relation ***"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RELATION_TY_SymmetricAdjective</span><span class="plain-syntax"> </span><span class="identifier-syntax">rel</span><span class="plain-syntax"> </span><span class="identifier-syntax">set</span><span class="plain-syntax">  </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax"> </span><span class="identifier-syntax">handler</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">) </span><span class="identifier-syntax">state</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">set</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> + </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax">)) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RlnSetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">handler</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_HANDLER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">handler</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RELS_SET_VALENCY</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">VALENCY_MASK</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="string-syntax">"*** Can't change this to a symmetric relation ***"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RELATION_TY_OToOAdjective</span><span class="plain-syntax"> </span><span class="identifier-syntax">rel</span><span class="plain-syntax"> </span><span class="identifier-syntax">set</span><span class="plain-syntax">  </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax"> </span><span class="identifier-syntax">handler</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; (</span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">+</span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) == </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">+</span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">state</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">set</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> + </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> + </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_EQUIVALENCE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_EQUIVALENCE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RlnSetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">handler</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_HANDLER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">handler</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RELS_SET_VALENCY</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">VALENCY_MASK</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="string-syntax">"*** Can't change this to a one-to-one relation ***"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RELATION_TY_OToVAdjective</span><span class="plain-syntax"> </span><span class="identifier-syntax">rel</span><span class="plain-syntax"> </span><span class="identifier-syntax">set</span><span class="plain-syntax">  </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax"> </span><span class="identifier-syntax">handler</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; (</span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">+</span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) == </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">state</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">set</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> + </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_EQUIVALENCE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_EQUIVALENCE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RlnSetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">handler</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_HANDLER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">handler</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RELS_SET_VALENCY</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">VALENCY_MASK</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="string-syntax">"*** Can't change this to a one-to-various relation ***"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RELATION_TY_VToOAdjective</span><span class="plain-syntax"> </span><span class="identifier-syntax">rel</span><span class="plain-syntax"> </span><span class="identifier-syntax">set</span><span class="plain-syntax">  </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax"> </span><span class="identifier-syntax">handler</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; (</span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">+</span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) == </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">state</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">set</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> + </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_SYMMETRIC</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_EQUIVALENCE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_EQUIVALENCE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RlnSetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">handler</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_HANDLER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">handler</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RELS_SET_VALENCY</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">VALENCY_MASK</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="string-syntax">"*** Can't change this to a various-to-one relation ***"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RELATION_TY_VToVAdjective</span><span class="plain-syntax"> </span><span class="identifier-syntax">rel</span><span class="plain-syntax"> </span><span class="identifier-syntax">set</span><span class="plain-syntax">  </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax"> </span><span class="identifier-syntax">handler</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; (</span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">+</span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">state</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">set</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">state</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> - </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">set</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">state</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> + </span><span class="identifier-syntax">RELS_X_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> = </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> + </span><span class="identifier-syntax">RELS_Y_UNIQUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RlnSetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">handler</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_HANDLER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">handler</span><span class="plain-syntax">(</span><span class="identifier-syntax">rel</span><span class="plain-syntax">, </span><span class="identifier-syntax">RELS_SET_VALENCY</span><span class="plain-syntax">, </span><span class="identifier-syntax">perms</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">VALENCY_MASK</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="string-syntax">"*** Can't change this to a various-to-various relation ***"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. One To One Relations.</b>We provide routines to assert a 1-to-1 relation true, or to assert it false.
The relation <span class="extract"><span class="extract-syntax">rel</span></span> is represented by a property number, and the property in
question is used to store the fact of a relationship: \(O_1\sim O_2\) if and
only if <span class="extract"><span class="extract-syntax">O1.rel == O2</span></span>.
</p>

<p class="commentary">There is no routine to test a 1-to-1 relation, since the predicate calculus
code in Inform simplifies propositions which test these into direct looking up
of the property relation.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_Now1to1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">ol</span><span class="plain-syntax">; </span><span class="comment-syntax">Assert 1-1 true</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">) </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ol</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ol</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> == </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">) </span><span class="identifier-syntax">ol</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowN1toV</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">; </span><span class="comment-syntax">Assert 1-1 false</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> == </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_Now1to1V</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">KOV</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">ol</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax">; </span><span class="comment-syntax">Assert 1-1 true</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ol</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">ol</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">ol</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">ol</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) == </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">ol</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowN1toVV</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">KOV</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">; </span><span class="comment-syntax">Assert 1-1 false</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) == </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Symmetric One To One Relations.</b>Here the relation is used for both objects: \(O_1\sim O_2\) if and only if
both <span class="extract"><span class="extract-syntax">O1.relation_property == O2</span></span> and <span class="extract"><span class="extract-syntax">O2.relation_property == O1</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowS1to1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">; </span><span class="comment-syntax">Assert symmetric 1-1 true</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) { (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">).</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) { (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">).</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">; </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowSN1to1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">; </span><span class="comment-syntax">Assert symmetric 1-1 false</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> == </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowS1to1V</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">KOV</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">; </span><span class="comment-syntax">Assert symmetric 1-1 true</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">), </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">), </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowSN1to1V</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">KOV</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">; </span><span class="comment-syntax">Assert symmetric 1-1 false</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) == </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. Various To Various Relations.</b>Here the relation is represented by an array holding its metadata. Each
object in the domain of the relation provides two properties, holding its
left index and its right index. The index is its position in the left or
right domain. For instance, suppose we relate things to doors, and there
are five things in the world, two of which are doors; then the left
indexes will range from 0 to 4, while the right indexes will range from
0 to 1. It's very likely that the doors will have different left and
right indexes. (If the relation relates a given kind to itself, say
doors to doors, then left and right indexes will always be equal.)
</p>

<p class="commentary">It is possible for either the left or right domain set to be an enumerated
kind of value, where the I6 representation of values is 1, 2, 3, ..., \(N\),
where there are \(N\) possibilities. In that case we obtain the index
simply by subtracting 1 in order to begin from 0. We mark the domain set
as being a KOV rather than a kind of object by storing 0 instead of a
property in the relevant part of the relation metadata: note that 0 is
not a valid property number.
</p>

<p class="commentary">The structure for a relation consists of eight <span class="extract"><span class="extract-syntax">--&gt;</span></span> words, followed by a
bitmap in which we store 16 bits in each <span class="extract"><span class="extract-syntax">--&gt;</span></span> word. (Yes, this is wasteful
in Glulx, where <span class="extract"><span class="extract-syntax">--&gt;</span></span> words store 32 bits, but memory is not in short supply
in Glulx and the total cost of relations is in practice small; we prefer
to keep all the code involved simple.) The structure is precompiled by the
Inform compiler: we do not create new ones on the fly.
</p>

<p class="commentary">In the case of a symmetric various to various relation, we could in theory
save memory once again by storing only the lower triangle of the bitmap,
but the time and complexity overhead are not worth it. When asserting that
\(O_1\sim O_2\) for a symmetric V-to-V, we also automatically assert that
\(O_2\sim O_1\), thus maintaining the bitmap as a symmetric matrix; but in
reading the bitmap, we look only at the lower triangle. This costs a little
time, but has the advantage of allowing the route-finding routine for
V-to-V to use the same code for symmetric and asymmetric relations.
</p>

<p class="commentary">If this all seems rather suboptimally programmed in order to reduce code
complexity, I can only say that careless drafts here were the source of
some extremely difficult bugs to find.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">VTOVS_LEFT_INDEX_PROP</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">VTOVS_RIGHT_INDEX_PROP</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">VTOVS_LEFT_DOMAIN_SIZE</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">VTOVS_RIGHT_DOMAIN_SIZE</span><span class="plain-syntax"> = </span><span class="constant-syntax">3</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">VTOVS_LEFT_PRINTING_ROUTINE</span><span class="plain-syntax"> = </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">VTOVS_RIGHT_PRINTING_ROUTINE</span><span class="plain-syntax"> = </span><span class="constant-syntax">5</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">VTOVS_CACHE_BROKEN</span><span class="plain-syntax"> = </span><span class="constant-syntax">6</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">VTOVS_CACHE</span><span class="plain-syntax"> = </span><span class="constant-syntax">7</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowVtoV</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">sym</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> </span><span class="identifier-syntax">i2</span><span class="plain-syntax"> </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sym</span><span class="plain-syntax"> &amp;&amp; (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">)) { </span><span class="identifier-syntax">Relation_NowVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="reserved-syntax">false</span><span class="plain-syntax">); }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_LEFT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_CACHE_BROKEN</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">; </span><span class="comment-syntax">Mark any cache as broken</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pr</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax">)) </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">pr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Relation_DomainProblem</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">-1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pr2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax">)) </span><span class="identifier-syntax">i2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">pr2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Relation_DomainProblem</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">i2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">-1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i1</span><span class="plain-syntax">*(</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_DOMAIN_SIZE</span><span class="plain-syntax">) + </span><span class="identifier-syntax">i2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">IncreasingPowersOfTwo_TB</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">pr</span><span class="plain-syntax">%16);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pr</span><span class="plain-syntax">/16 + </span><span class="constant-syntax">8</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">pr</span><span class="plain-syntax">) | </span><span class="identifier-syntax">i1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowNVtoV</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">sym</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> </span><span class="identifier-syntax">i2</span><span class="plain-syntax"> </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sym</span><span class="plain-syntax"> &amp;&amp; (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">)) { </span><span class="identifier-syntax">Relation_NowNVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="reserved-syntax">false</span><span class="plain-syntax">); }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_LEFT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_CACHE_BROKEN</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">; </span><span class="comment-syntax">Mark any cache as broken</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pr</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax">)) </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">pr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Relation_DomainProblem</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">-1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pr2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax">)) </span><span class="identifier-syntax">i2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">pr2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Relation_DomainProblem</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">i2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">-1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i1</span><span class="plain-syntax">*(</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_DOMAIN_SIZE</span><span class="plain-syntax">) + </span><span class="identifier-syntax">i2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">IncreasingPowersOfTwo_TB</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">pr</span><span class="plain-syntax">%16);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pr</span><span class="plain-syntax">/16 + </span><span class="constant-syntax">8</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">pr</span><span class="plain-syntax">) &amp; </span><span class="identifier-syntax">i1</span><span class="plain-syntax">) </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">pr</span><span class="plain-syntax"> - </span><span class="identifier-syntax">i1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">sym</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> </span><span class="identifier-syntax">i2</span><span class="plain-syntax"> </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_LEFT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sym</span><span class="plain-syntax"> &amp;&amp; (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">)) { </span><span class="identifier-syntax">sym</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">; </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">; </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">sym</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pr</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax">)) </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">pr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> { </span><span class="identifier-syntax">Relation_DomainProblem</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">); </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">-1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pr2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax">)) </span><span class="identifier-syntax">i2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">pr2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> { </span><span class="identifier-syntax">Relation_DomainProblem</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">); </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">i2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">-1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i1</span><span class="plain-syntax">*(</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_DOMAIN_SIZE</span><span class="plain-syntax">) + </span><span class="identifier-syntax">i2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">IncreasingPowersOfTwo_TB</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">pr</span><span class="plain-syntax">%16);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pr</span><span class="plain-syntax">/16 + </span><span class="constant-syntax">8</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">pr</span><span class="plain-syntax">) &amp; </span><span class="identifier-syntax">i1</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">; </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_DomainProblem</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"RelationUsedOutsideDomain"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"Used a relation with something outside its domain"</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"*** Use of "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">the</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">" violates '"</span><span class="plain-syntax">, (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Equivalence Relations.</b>For every equivalence relation there is a corresponding function \(f\) such
that \(x\sim y\) if and only if \(f(x)=f(y)\), where \(f(x)\) is a number identifying
the equivalence class of \(x\). Rather than inefficiently storing a large
relation bitmap (and then having a very complicated time updating it to
keep the relation transitive), we store \(f\): that is, for every object in
the domain set, there is a property <span class="extract"><span class="extract-syntax">prop</span></span> such that <span class="extract"><span class="extract-syntax">O.prop</span></span> is the value
\(f(O)\).
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowEquiv</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">big</span><span class="plain-syntax"> </span><span class="identifier-syntax">little</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">big</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">; </span><span class="identifier-syntax">little</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">big</span><span class="plain-syntax"> == </span><span class="identifier-syntax">little</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">big</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">little</span><span class="plain-syntax">) { </span><span class="identifier-syntax">little</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">; </span><span class="identifier-syntax">big</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> == </span><span class="identifier-syntax">big</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">little</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowNEquiv</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">old</span><span class="plain-syntax"> </span><span class="identifier-syntax">new</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">old</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">; </span><span class="identifier-syntax">new</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">old</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">new</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">new</span><span class="plain-syntax">) </span><span class="identifier-syntax">new</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowEquivV</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">KOV</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> </span><span class="identifier-syntax">big</span><span class="plain-syntax"> </span><span class="identifier-syntax">little</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">big</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">little</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">big</span><span class="plain-syntax"> == </span><span class="identifier-syntax">little</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">big</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">little</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">little</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">big</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">n</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) == </span><span class="identifier-syntax">big</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="identifier-syntax">little</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_NowNEquivV</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">KOV</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> </span><span class="identifier-syntax">old</span><span class="plain-syntax"> </span><span class="identifier-syntax">new</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">old</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">old</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">new</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">n</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) &gt; </span><span class="identifier-syntax">new</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">new</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="identifier-syntax">new</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. Show Various to Various.</b>The rest of the code for relations has no use except for debugging: it
implements the RELATIONS testing command. Speed is unimportant here.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_ShowVtoV</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">sym</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> </span><span class="identifier-syntax">proutine1</span><span class="plain-syntax"> </span><span class="identifier-syntax">proutine2</span><span class="plain-syntax"> </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_LEFT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">proutine1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_LEFT_PRINTING_ROUTINE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">proutine2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_PRINTING_ROUTINE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pr</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">pr2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax">)</span>
<span class="plain-syntax">          </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sym</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">; </span><span class="identifier-syntax">x</span><span class="plain-syntax">=1; }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">The</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sym</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  &lt;=&gt;  "</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  &gt;=&gt;  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="identifier-syntax">the</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">          }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pr</span><span class="plain-syntax"> &amp;&amp; (</span><span class="identifier-syntax">pr2</span><span class="plain-syntax">==0)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax">)</span>
<span class="plain-syntax">          </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_DOMAIN_SIZE</span><span class="plain-syntax">:</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">; </span><span class="identifier-syntax">x</span><span class="plain-syntax">=1; }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">The</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="string-syntax">"  &gt;=&gt;  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">proutine2</span><span class="plain-syntax">.</span><span class="identifier-syntax">call</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">          }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">pr</span><span class="plain-syntax">==0) &amp;&amp; (</span><span class="identifier-syntax">pr2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;2:</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">          </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">; </span><span class="identifier-syntax">x</span><span class="plain-syntax">=1; }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">proutine1</span><span class="plain-syntax">.</span><span class="identifier-syntax">call</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  &gt;=&gt;  "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">the</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">          }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;2:</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">          </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_DOMAIN_SIZE</span><span class="plain-syntax">:</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">; </span><span class="identifier-syntax">x</span><span class="plain-syntax">=1; }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">proutine1</span><span class="plain-syntax">.</span><span class="identifier-syntax">call</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  &gt;=&gt;  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">proutine2</span><span class="plain-syntax">.</span><span class="identifier-syntax">call</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">          }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. Show One to One.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_ShowOtoO</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">sym</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax"> </span><span class="identifier-syntax">tr</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindConstructorTerm</span><span class="plain-syntax">(</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_KIND</span><span class="plain-syntax">), </span><span class="constant-syntax">0</span><span class="plain-syntax">); </span><span class="comment-syntax">Kind of left term</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">tr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindConstructorTerm</span><span class="plain-syntax">(</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_KIND</span><span class="plain-syntax">), </span><span class="constant-syntax">1</span><span class="plain-syntax">); </span><span class="comment-syntax">Kind of right term</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax"> == </span><span class="identifier-syntax">OBJECT_TY</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sym</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">; </span><span class="identifier-syntax">x</span><span class="plain-syntax">=1; }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">The</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sym</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  ==  "</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  &gt;=&gt;  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">tr</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sym</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">; </span><span class="identifier-syntax">x</span><span class="plain-syntax">=1; }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sym</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  ==  "</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  &gt;=&gt;  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">tr</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. Show Reversed One to One.</b>There's no such kind of relation as this: but the same code used to show
1-to-1 relations is also used to show various-to-1 relations, since the
storage is the same. To show 1-to-various relations, we need a transposed
form of the same code in which left and right are exchanged: this is it.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_RShowOtoO</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">sym</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">t1</span><span class="plain-syntax"> </span><span class="identifier-syntax">t2</span><span class="plain-syntax"> </span><span class="identifier-syntax">N1</span><span class="plain-syntax"> </span><span class="identifier-syntax">N2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindConstructorTerm</span><span class="plain-syntax">(</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_KIND</span><span class="plain-syntax">), </span><span class="constant-syntax">0</span><span class="plain-syntax">); </span><span class="comment-syntax">Kind of left term</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindConstructorTerm</span><span class="plain-syntax">(</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_KIND</span><span class="plain-syntax">), </span><span class="constant-syntax">1</span><span class="plain-syntax">); </span><span class="comment-syntax">Kind of right term</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t2</span><span class="plain-syntax"> == </span><span class="identifier-syntax">OBJECT_TY</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">OBJECT_TY</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">; </span><span class="identifier-syntax">x</span><span class="plain-syntax">=1; }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">The</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  &gt;=&gt;  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="identifier-syntax">the</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">N1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">t1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N1</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">; </span><span class="identifier-syntax">x</span><span class="plain-syntax">=1; }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">; </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">t1</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  &gt;=&gt;  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="identifier-syntax">the</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">N2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">OBJECT_TY</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N2</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) ~= </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">; </span><span class="identifier-syntax">x</span><span class="plain-syntax">=1; }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">The</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  &gt;=&gt;  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">N1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">t1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N1</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N2</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) ~= </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">; </span><span class="identifier-syntax">x</span><span class="plain-syntax">=1; }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">t1</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  &gt;=&gt;  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. Show Equivalence.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">RSE_Flip</span><span class="plain-syntax"> </span><span class="identifier-syntax">KOV</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">x</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">v</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">); </span><span class="identifier-syntax">x</span><span class="plain-syntax"> = -</span><span class="identifier-syntax">x</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">v</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="identifier-syntax">x</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">RSE_Set</span><span class="plain-syntax"> </span><span class="identifier-syntax">KOV</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">KOV</span><span class="plain-syntax">, </span><span class="identifier-syntax">v</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">; </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_ShowEquiv</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax"> </span><span class="identifier-syntax">d</span><span class="plain-syntax"> </span><span class="identifier-syntax">somegroups</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_DESCRIPTION</span><span class="plain-syntax">), </span><span class="string-syntax">":^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindConstructorTerm</span><span class="plain-syntax">(</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_KIND</span><span class="plain-syntax">), </span><span class="constant-syntax">0</span><span class="plain-syntax">); </span><span class="comment-syntax">Kind of left term</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax"> == </span><span class="identifier-syntax">OBJECT_TY</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = -(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">; </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">has</span><span class="plain-syntax"> </span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">) </span><span class="reserved-syntax">give</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> ~</span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> == </span><span class="identifier-syntax">v</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">give</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = -</span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">c</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax">&gt;1) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">somegroups</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  { "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">WriteListOfMarkedObjects</span><span class="plain-syntax">(</span><span class="identifier-syntax">ENGLISH_BIT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" }^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">has</span><span class="plain-syntax"> </span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">) </span><span class="reserved-syntax">give</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> ~</span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="identifier-syntax">c</span><span class="plain-syntax">++; </span><span class="reserved-syntax">give</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">somegroups</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  and "</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">4</span><span class="plain-syntax">) { </span><span class="identifier-syntax">WriteListOfMarkedObjects</span><span class="plain-syntax">(</span><span class="identifier-syntax">ENGLISH_BIT</span><span class="plain-syntax">); </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" in"</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" a"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" single-member group"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"s"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = -(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="comment-syntax">A slower method, since we have less efficient storage:</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">RSE_Flip</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">RSE_Set</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) == </span><span class="identifier-syntax">v</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">c</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax">&gt;1) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">somegroups</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  {"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">d</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) == </span><span class="identifier-syntax">v</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" "</span><span class="plain-syntax">; </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">d</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">c</span><span class="plain-syntax">-1) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">","</span><span class="plain-syntax">; </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">RSE_Flip</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">d</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">                        }</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"}^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="identifier-syntax">v</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">has</span><span class="plain-syntax"> </span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">) </span><span class="reserved-syntax">give</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> ~</span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">RSE_Set</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)) </span><span class="identifier-syntax">c</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">somegroups</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  and "</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"  "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"a"</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" single-member group"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"s"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">RSE_Set</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">RSE_Flip</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. Relation Emptying.</b>These routines, mercifully a little simpler, define the adjective "empty" as
it applied to relations. Each routine has to forcibly empty the relation if
the clear flag is set, and in any case return either true or false to say
whether the relation is empty at the end of the call. For relations in groups,
"empty" is understood to mean that each object relates only to itself.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_EmptyOtoO</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">sym</span><span class="plain-syntax"> </span><span class="identifier-syntax">clear</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind1</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind2</span><span class="plain-syntax"> </span><span class="identifier-syntax">N1</span><span class="plain-syntax"> </span><span class="identifier-syntax">N2</span><span class="plain-syntax"> </span><span class="identifier-syntax">pval</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">kind1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindConstructorTerm</span><span class="plain-syntax">(</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_KIND</span><span class="plain-syntax">), </span><span class="constant-syntax">0</span><span class="plain-syntax">); </span><span class="comment-syntax">Kind of left term</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">kind2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindConstructorTerm</span><span class="plain-syntax">(</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_KIND</span><span class="plain-syntax">), </span><span class="constant-syntax">1</span><span class="plain-syntax">); </span><span class="comment-syntax">Kind of right term</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">kind2</span><span class="plain-syntax"> == </span><span class="identifier-syntax">OBJECT_TY</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">K0_kind</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">pval</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ix</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pval</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">clear</span><span class="plain-syntax">) </span><span class="identifier-syntax">ix</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">N2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">kind2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">ix</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N2</span><span class="plain-syntax">: </span><span class="identifier-syntax">ix</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">pval</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">kind2</span><span class="plain-syntax">, </span><span class="identifier-syntax">ix</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pval</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">clear</span><span class="plain-syntax">) </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">kind2</span><span class="plain-syntax">, </span><span class="identifier-syntax">ix</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">kind1</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">kind2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">kind1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">OBJECT_TY</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">K0_kind</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">pval</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ix</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pval</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">clear</span><span class="plain-syntax">) </span><span class="identifier-syntax">ix</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">N1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">kind1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">ix</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N1</span><span class="plain-syntax">: </span><span class="identifier-syntax">ix</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">pval</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">kind1</span><span class="plain-syntax">, </span><span class="identifier-syntax">ix</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pval</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">clear</span><span class="plain-syntax">) </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">kind1</span><span class="plain-syntax">, </span><span class="identifier-syntax">ix</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_EmptyEquiv</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">sym</span><span class="plain-syntax"> </span><span class="identifier-syntax">clear</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindConstructorTerm</span><span class="plain-syntax">(</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_KIND</span><span class="plain-syntax">), </span><span class="constant-syntax">0</span><span class="plain-syntax">); </span><span class="comment-syntax">Kind of left term</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindDomainSize</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">clear</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax"> == </span><span class="identifier-syntax">OBJECT_TY</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> = </span><span class="identifier-syntax">v</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">, </span><span class="identifier-syntax">v</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax"> == </span><span class="identifier-syntax">OBJECT_TY</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> == </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">=</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">+1: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">N</span><span class="plain-syntax">: </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) == </span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">Relation_EmptyVtoV</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">sym</span><span class="plain-syntax"> </span><span class="identifier-syntax">clear</span><span class="plain-syntax"> </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> </span><span class="identifier-syntax">proutine1</span><span class="plain-syntax"> </span><span class="identifier-syntax">proutine2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_LEFT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">proutine1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_LEFT_PRINTING_ROUTINE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">proutine2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_PRINTING_ROUTINE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pr</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">pr2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sym</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">obj1</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">clear</span><span class="plain-syntax">) </span><span class="identifier-syntax">Relation_NowNVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">sym</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pr</span><span class="plain-syntax"> &amp;&amp; (</span><span class="identifier-syntax">pr2</span><span class="plain-syntax">==0)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_DOMAIN_SIZE</span><span class="plain-syntax">:</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">clear</span><span class="plain-syntax">) </span><span class="identifier-syntax">Relation_NowNVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">sym</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">pr</span><span class="plain-syntax">==0) &amp;&amp; (</span><span class="identifier-syntax">pr2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;2:</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">clear</span><span class="plain-syntax">) </span><span class="identifier-syntax">Relation_NowNVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">sym</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;2:</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_DOMAIN_SIZE</span><span class="plain-syntax">:</span><span class="identifier-syntax">obj2</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">clear</span><span class="plain-syntax">) </span><span class="identifier-syntax">Relation_NowNVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj1</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">, </span><span class="identifier-syntax">sym</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. Relation Route-Finding.</b>The general problem we have to solve here is: given \(x, y\in D\), where \(\sim\)
is a relation on a domain set \(D\) of objects,
</p>

<ul class="items"><li>(i) find the smallest \(n\) such that there exist $x = r_1\sim r_2\sim ...\sim
r_n = y\in D\( such that \)r_i\sim r_{i+1}\(, or determine that no such \)n$ exists,
and if so
</li><li>(ii) find a value of \(r_2\) in such a "route" between \(x\) and \(y\), or
set \(r_2=0\) if \(x=y\) so that \(n=1\).
</li></ul>
<p class="commentary">While in general a relation can have different left and right domains (a
relation between doors and rooms, say), route-finding on those relations is
unlikely to be very useful, so is discouraged. (In the case of doors and
rooms, a route could never be longer than 1 step, since no object is both a
door and a room, for instance.) The "fast" V-to-V algorithm requires \(D\)
to have the same left and right domains; Inform compiles the memory caches for
V-to-V relations to force any cases with different domains into using the
"slow" algorithm.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">MAX_ROUTE_LENGTH</span></span> is used simply as a sanity check to prevent hangs if
something should go wrong, for instance if the property of a 1-to-V
relation has been modified by some third-party code in such a way that
it loses its defining invariant.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">MAX_ROUTE_LENGTH</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ICOUNT_OBJECT</span><span class="plain-syntax"> + </span><span class="constant-syntax">32</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RelationRouteTo</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="reserved-syntax">to</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">  </span><span class="identifier-syntax">handler</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">from</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="reserved-syntax">to</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">relation</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">from</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="reserved-syntax">to</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">relation</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">from</span><span class="plain-syntax"> == </span><span class="reserved-syntax">to</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_PERMISSIONS</span><span class="plain-syntax">)) &amp; </span><span class="identifier-syntax">RELS_ROUTE_FIND</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"RoutesThroughImplicitRelation"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"Attempt to find route or count steps through an implicit relation."</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">handler</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_HANDLER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">handler</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RELS_ROUTE_FIND_COUNT</span><span class="plain-syntax">, </span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="reserved-syntax">to</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">handler</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RELS_ROUTE_FIND</span><span class="plain-syntax">, </span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="reserved-syntax">to</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RelFollowVector</span><span class="plain-syntax"> </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="reserved-syntax">to</span><span class="plain-syntax">  </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">from</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj</span><span class="plain-syntax"> ~= </span><span class="reserved-syntax">to</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">MAX_ROUTE_LENGTH</span><span class="plain-syntax">)) { </span><span class="identifier-syntax">i</span><span class="plain-syntax">++; </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. One To Various Route-Finding.</b>Here we can immediately determine, given \(y\), the unique \(y'\) such that
\(y'\sim y\), so finding a path from \(x\) to \(y\) is a matter of following the
only path leading to \(y\) and seeing if it ever passed through \(x\); thus the
running time is \(O(n)\), where \(n\) is the size of the domain. It would be
pointless to cache this.
</p>

<p class="commentary">Note that we can assume here that \(x\neq y\), or rather, that <span class="extract"><span class="extract-syntax">from ~= to</span></span>,
because that case has already been taken care of.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">OtoVRelRouteTo</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="reserved-syntax">to</span><span class="plain-syntax"> </span><span class="identifier-syntax">previous</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ((</span><span class="reserved-syntax">to</span><span class="plain-syntax">) &amp;&amp; (</span><span class="reserved-syntax">to</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) &amp;&amp; (</span><span class="reserved-syntax">to</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">previous</span><span class="plain-syntax"> = </span><span class="reserved-syntax">to</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">previous</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax"> = </span><span class="reserved-syntax">to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">previous</span><span class="plain-syntax"> == </span><span class="identifier-syntax">from</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">previous</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. Various To One Route-Finding.</b>This time the simplifying assumption is that, given \(x\), we can immediately
determine the unique \(x'\) such that \(x\sim x'\), so it suffices to follow
the only path forwards from \(x\) and see if it ever reaches \(y\). The routine
is not quite a mirror image of the one above, because both have the same
return requirements: we have to ensure that the <span class="extract"><span class="extract-syntax">vector</span></span> properties lay out
the path, and also return the next step after \(x\).
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VtoORelRouteTo</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="reserved-syntax">to</span><span class="plain-syntax"> </span><span class="identifier-syntax">next</span><span class="plain-syntax">  </span><span class="identifier-syntax">start</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">start</span><span class="plain-syntax"> = </span><span class="identifier-syntax">from</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">from</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">from</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">next</span><span class="plain-syntax"> = </span><span class="identifier-syntax">from</span><span class="plain-syntax">.</span><span class="identifier-syntax">relation_property</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">from</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax"> = </span><span class="identifier-syntax">next</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">next</span><span class="plain-syntax"> == </span><span class="reserved-syntax">to</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">start</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">from</span><span class="plain-syntax"> = </span><span class="identifier-syntax">next</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. Slow Various To Various Route-Finding.</b>Now there are no simplifying assumptions and the problem is essentially the
same as the one solved for route-finding in the map, above. Once again we
present two different algorithms: first, a form of Prim's algorithm for
minimal spanning trees. Note that, whereas this algorithm was not always
so "slow" for the map &mdash; because of the fairly low vertex degrees involved,
i.e., because most rooms had few connections to other rooms &mdash; here the
relation might well be almost complete, with almost all the objects related
to each other, and then the algorithm will indeed be "slow". So it is
likely that the "fast" algorithm will always be better, if the memory
can be spared for it.
</p>

<p class="commentary">We use the fast algorithm for a given relation if and only if the Inform compiler
has allocated the necessary cache memory; the two use options above, for
map route-finding, don't control this.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VtoVRelRouteTo</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="reserved-syntax">to</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="identifier-syntax">related</span><span class="plain-syntax"> </span><span class="identifier-syntax">progressed</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_CACHE</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FastVtoVRelRouteTo</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="reserved-syntax">to</span><span class="plain-syntax">, </span><span class="identifier-syntax">count</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_LEFT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">vtov_structure</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">VTOVS_RIGHT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">vector</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">to</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="reserved-syntax">true</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">progressed</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">pr2</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj2</span><span class="plain-syntax"> | </span><span class="identifier-syntax">WORD_HIGHBIT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">progressed</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax"> &amp;~ </span><span class="identifier-syntax">WORD_HIGHBIT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">from</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">progressed</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">from</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">from</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj</span><span class="plain-syntax"> ~= </span><span class="reserved-syntax">to</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">MAX_ROUTE_LENGTH</span><span class="plain-syntax">)) { </span><span class="identifier-syntax">i</span><span class="plain-syntax">++; </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax">.</span><span class="identifier-syntax">vector</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. Fast Various To Various Route-Finding.</b>Now, as above, a form of the Floyd-Warshall algorithm. The matrix is here
stored in the cache of memory pointed to in the V-to-V relation structure.
We are unable to combine \(a_{ij}\) and \(d_{ij}\) into a single cell of
memory, so in fact we store two separate matrices: one for \(a_{ij}\)
(this is <span class="extract"><span class="extract-syntax">cache</span></span> below), the other for \(n_{ij}\), where \(n_{ij}\) is the
next object in the shortest path from \(O_i\) to \(O_j\) (this is <span class="extract"><span class="extract-syntax">cache2</span></span>
below).
</p>

<p class="commentary">Where \(n&lt;256\) a shortest path must be such that \(a_{ij}\leq 255\), so can
be stored in a single byte, and we similarly store \(n_{ij}\) as the index
of the object rather than the object value itself: the index ranges from
0 to \(n-1\), so that \(0\leq n_{ij} &lt; 255\) and we can use \(n_{ij} = 255\)
as a sentinel value meaning "no path". Although the reconversion of
\(n_{ij}\) back into a valid object value takes a little time, it is only
\(O(n)\), and of course we know \(n\) is relatively small; and in this way
we reduce the storage overhead to only \(n^2\) bytes.
</p>

<p class="commentary">Where \(n\geq 256\), we resign ourselves to storing two words for each pair
\((i,j)\), making \(2n^2\) bytes of storage on the Z-machine and \(4n^2\) bytes
of storage on Glulx, but lookup of a cached result is slightly faster.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">FastVtoVRelRouteTo</span><span class="plain-syntax"> </span><span class="identifier-syntax">relation</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="reserved-syntax">to</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> </span><span class="identifier-syntax">cache</span><span class="plain-syntax"> </span><span class="identifier-syntax">cache2</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">ox</span><span class="plain-syntax"> </span><span class="identifier-syntax">oy</span><span class="plain-syntax"> </span><span class="identifier-syntax">oj</span><span class="plain-syntax"> </span><span class="identifier-syntax">offset</span><span class="plain-syntax"> </span><span class="identifier-syntax">axy</span><span class="plain-syntax"> </span><span class="identifier-syntax">axj</span><span class="plain-syntax"> </span><span class="identifier-syntax">ayj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">)--&gt;2; </span><span class="comment-syntax">Number of left instances</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">)--&gt;</span><span class="identifier-syntax">VTOVS_LEFT_INDEX_PROP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">) &amp;&amp; (</span><span class="reserved-syntax">to</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">256</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">cache</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">)--&gt;</span><span class="identifier-syntax">VTOVS_CACHE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">cache2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache</span><span class="plain-syntax"> + </span><span class="identifier-syntax">domainsize</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">)--&gt;</span><span class="identifier-syntax">VTOVS_CACHE_BROKEN</span><span class="plain-syntax"> == </span><span class="reserved-syntax">true</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">)--&gt;</span><span class="identifier-syntax">VTOVS_CACHE_BROKEN</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oy</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ox</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">oy</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">ox</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">oy</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + (</span><span class="identifier-syntax">ox</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">cache</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">cache2</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ox</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">oy</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + (</span><span class="identifier-syntax">ox</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">cache</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">cache2</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="constant-syntax">255</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oy</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">oy</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax">: </span><span class="identifier-syntax">oy</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ox</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">ox</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax">: </span><span class="identifier-syntax">ox</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">axy</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">ox</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + </span><span class="identifier-syntax">oy</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">axy</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oj</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">oj</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax">: </span><span class="identifier-syntax">oj</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                                </span><span class="identifier-syntax">ayj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">oy</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + </span><span class="identifier-syntax">oj</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ayj</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                                    </span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ox</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + </span><span class="identifier-syntax">oj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                                    </span><span class="identifier-syntax">axj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">axj</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">axy</span><span class="plain-syntax"> + </span><span class="identifier-syntax">ayj</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">axj</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                                        </span><span class="identifier-syntax">cache</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">axy</span><span class="plain-syntax"> + </span><span class="identifier-syntax">ayj</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                                        </span><span class="identifier-syntax">cache2</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache2</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">ox</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + </span><span class="identifier-syntax">oy</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                                    }</span>
<span class="plain-syntax">                                }</span>
<span class="plain-syntax">                            }</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache</span><span class="plain-syntax">-&gt;((</span><span class="identifier-syntax">from</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + (</span><span class="reserved-syntax">to</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">oy</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache2</span><span class="plain-syntax">-&gt;((</span><span class="identifier-syntax">from</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + (</span><span class="reserved-syntax">to</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oy</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">255</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ox</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ox</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax"> == </span><span class="identifier-syntax">oy</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ox</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">cache</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">)--&gt;</span><span class="identifier-syntax">VTOVS_CACHE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">cache2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache</span><span class="plain-syntax"> + </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">)--&gt;</span><span class="identifier-syntax">VTOVS_CACHE_BROKEN</span><span class="plain-syntax"> == </span><span class="reserved-syntax">true</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">RlnGetF</span><span class="plain-syntax">(</span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">RR_STORAGE</span><span class="plain-syntax">)--&gt;</span><span class="identifier-syntax">VTOVS_CACHE_BROKEN</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oy</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ox</span><span class="plain-syntax"> </span><span class="reserved-syntax">provides</span><span class="plain-syntax"> </span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Relation_TestVtoV</span><span class="plain-syntax">(</span><span class="identifier-syntax">oy</span><span class="plain-syntax">, </span><span class="identifier-syntax">relation</span><span class="plain-syntax">, </span><span class="identifier-syntax">ox</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">oy</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + (</span><span class="identifier-syntax">ox</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">cache</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">cache2</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ox</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">oy</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + (</span><span class="identifier-syntax">ox</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">cache</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">cache2</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oy</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">oy</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax">: </span><span class="identifier-syntax">oy</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ox</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">ox</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax">: </span><span class="identifier-syntax">ox</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">axy</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">ox</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + </span><span class="identifier-syntax">oy</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">axy</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oj</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">oj</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax">: </span><span class="identifier-syntax">oj</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                                </span><span class="identifier-syntax">ayj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">oy</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + </span><span class="identifier-syntax">oj</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ayj</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                                    </span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ox</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + </span><span class="identifier-syntax">oj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                                    </span><span class="identifier-syntax">axj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">axj</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">axy</span><span class="plain-syntax"> + </span><span class="identifier-syntax">ayj</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">axj</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                                        </span><span class="identifier-syntax">cache</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">axy</span><span class="plain-syntax"> + </span><span class="identifier-syntax">ayj</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                                        </span><span class="identifier-syntax">cache2</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">offset</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache2</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">ox</span><span class="plain-syntax">*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + </span><span class="identifier-syntax">oy</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                                    }</span>
<span class="plain-syntax">                                }</span>
<span class="plain-syntax">                            }</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cache</span><span class="plain-syntax">--&gt;((</span><span class="identifier-syntax">from</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + (</span><span class="reserved-syntax">to</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">cache2</span><span class="plain-syntax">--&gt;((</span><span class="identifier-syntax">from</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">)*</span><span class="identifier-syntax">domainsize</span><span class="plain-syntax"> + (</span><span class="reserved-syntax">to</span><span class="plain-syntax">.</span><span class="identifier-syntax">left_ix</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>&#167;17. Iterating Relations.</b>The following is provided to make it possible to run an I6 routine on each
relation in turn. (Each right-way-round relation, at any rate.)
</p>

<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="rltnk.html">&#10094;</a></li><li class="progresssection"><a href="dfntn.html">dfntn</a></li><li class="progresssection"><a href="strtp.html">strtp</a></li><li class="progresssection"><a href="utlts.html">utlts</a></li><li class="progresssection"><a href="prgrp.html">prgrp</a></li><li class="progresssection"><a href="mthmt.html">mthmt</a></li><li class="progresssection"><a href="srt.html">srt</a></li><li class="progresssection"><a href="tbls.html">tbls</a></li><li class="progresssection"><a href="mstck.html">mstck</a></li><li class="progresssection"><a href="rlbks.html">rlbks</a></li><li class="progresssection"><a href="actvt.html">actvt</a></li><li class="progresssection"><a href="prntn.html">prntn</a></li><li class="progresssection"><a href="flx.html">flx</a></li><li class="progresssection"><a href="blckv.html">blckv</a></li><li class="progresssection"><a href="knds.html">knds</a></li><li class="progresssection"><a href="txt.html">txt</a></li><li class="progresssection"><a href="chr.html">chr</a></li><li class="progresssection"><a href="rgxp.html">rgxp</a></li><li class="progresssection"><a href="lsts.html">lsts</a></li><li class="progresssection"><a href="cmbnt.html">cmbnt</a></li><li class="progresssection"><a href="rltnk.html">rltnk</a></li><li class="progresscurrent">rltns</li><li class="progresssection"><a href="prprt.html">prprt</a></li><li class="progresssection"><a href="rtp.html">rtp</a></li><li class="progressnext"><a href="prprt.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

